-
Notifications
You must be signed in to change notification settings - Fork 28.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-35800][SS] Improving GroupState testability by introducing TestGroupState #32938
[SPARK-35800][SS] Improving GroupState testability by introducing TestGroupState #32938
Conversation
Can one of the admins verify this patch? |
Hello @lizhangdatabricks , welcome to the Apache Spark community! I'd like to recommend you to take some time to read the section of Contributing Code Changes in contribution page in Apache Spark website - http://spark.apache.org/contributing.html Shall we check your proposal with the steps and update it after reading? |
Hi Jungtaek,
Sure! I can read through the guidelines and update accordingly.
Will ping you again for the review after updates!
Thanks,
Li
…On Wed, Jun 16, 2021 at 8:25 PM Jungtaek Lim ***@***.***> wrote:
Hello @lizhangdatabricks <https://github.com/lizhangdatabricks> , welcome
to the Apache Spark community!
I'd like to recommend you to take some time to read the section of *Contributing
Code Changes* in contribution page in Apache Spark website -
http://spark.apache.org/contributing.html
Shall we check your proposal with the steps and update it after reading?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#32938 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUJMP2EE7NZ7X6ZR3GQLOGDTTFTJRANCNFSM462JIDJQ>
.
|
Please fill the content of the PR accordingly based on PR template on Apache Spark community's guideline. https://github.com/apache/spark/blob/master/.github/PULL_REQUEST_TEMPLATE Let's try not to remote/skip any section in the template. You can seek some approved PRs and see how these PRs fill the content. |
*/ | ||
trait TestGroupState[S] extends GroupState[S] { | ||
/** Whether the state has been marked for removing */ | ||
def hasRemoved: Boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think isRemoved and isUpdated are better.
* | ||
* @tparam S User-defined type of the state to be stored for each group. Must be encodable into | ||
* Spark SQL types (see `Encoder` for more details). | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the original GroupState API is still marked as experimental (I know it does make sense, but that's for a different discussion), lets be consistent and add the same annotations to this as well. similarly, also add @since 3.2.0
and would be nice if you could add Java and Scala code snippets of how to use these traits. It's not entirely obvious how to use TestGroupState. See GroupState to find out how to add code snippets. This is how it looks later - https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.sql.streaming.GroupState
…ed to isRemoved/isUpdated; Fix lint errors
* // with desired configs. The create() API would guarantee that | ||
* // the generated instance has the same behavior as the one built by | ||
* // engine with the same configs. | ||
* var prevState = TestGroupState.create[UserStatus]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why is this a var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not be consistent with the docs of GroupState by using the same names and types. like the function name over there is mappingFunction
and data types are String, Int, and Int?
* // engine with the same configs. | ||
* var prevState = TestGroupState.create[UserStatus]( | ||
* optionalState = Optional.empty[UserStatus], | ||
* timeoutConf = EventTimeTimeout, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets keep this simple...NoTimeout
* | ||
* // Calls the state transition function with the test previous state | ||
* // with desired configs. | ||
* updateState(userId, actions, prevState) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you are sticking to new names, then at least define updateState as the function that is going to be used with map/flatmapGroupsWithState
def isUpdated: Boolean | ||
|
||
/** | ||
* Returns the timestamp if setTimeoutTimestamp is called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to the corresponding functions in GroupState. If thats complicated, at least put the function names and codee snippets in backticks
`setTimeoutTimestamp` `setTimeoutDuration`
`Optional.empty`
and Or returns batch processing time + the duration...
keeps the verb tense consistent with the previous "Returns the timestamp"
* @return a [[TestGroupState]] instance that's built with the user specified configs. | ||
*/ | ||
@throws[IllegalArgumentException]("if 'batchProcessingTimeMs' is not positive") | ||
@throws[IllegalArgumentException]("if 'eventTimeWatermarkMs' present but is not 0 or positive") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is present but is < 0
not X or Y
is a sometimes a little ambiguous to parse in english. is it !x || y
or !(x || y)
* // engine with the same configs. | ||
* TestGroupState prevState = new TestGroupState<UserStatus>().create( | ||
* optionalState = Optional.<UserStatus>empty(), | ||
* timeoutConf = EventTimeTimeout, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments as above.
sql/core/src/test/scala/org/apache/spark/sql/streaming/FlatMapGroupsWithStateSuite.scala
Show resolved
Hide resolved
* will be supported. | ||
* @param batchProcessingTimeMs Processing time of current batch, used to calculate timestamp | ||
* for processing time timeouts. | ||
* @param eventTimeWatermarkMs Optional value of event time watermark in ms. Set as None if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: None
is not correct. its Optional.empty . isnt it?
import org.apache.spark.sql.execution.streaming.GroupStateImpl._ | ||
|
||
/** | ||
* The extended version of [[GroupState]] interface with extra getters of state machine fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need htis as well
::Experimental::
See GroupState
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes. This is going to be very useful!
What changes were proposed in this pull request?
Proposed changes in this pull request:
TestGroupState
interface which is inherited fromGroupState
so that testing related getters can be exposed in a controlled mannerGroupStateImpl
to inherit fromTestGroupState
interface, instead of directly fromGroupState
TestGroupState
object withcreate()
method to forward inputs to the privateGroupStateImpl
constructorGroupStateImpl
'screateForStreaming()
method to prevent users from creating invalid GroupState objects.GroupStateImpl
usages in sql pkg internal unit tests with the newly addedTestGroupState
to give user best practice aboutTestGroupState
usage.With the changes in this PR, the class hierarchy is changed from
GroupStateImpl
->GroupState
toGroupStateImpl
->TestGroupState
->GroupState
(-> means inherits from)Why are the changes needed?
The internal
GroupStateImpl
implementation for theGroupState
interface has no public constructors accessible outside of the sql pkg. However, the user-provided state transition function for[map|flatMap]GroupsWithState
requires aGroupState
object as the prevState input.Currently, users are calling the Structured Streaming engine in their unit tests in order to instantiate such
GroupState
instances, which makes UTs cumbersome.The proposed
TestGroupState
interface is to give users controlled access to theGroupStateImpl
internal implementation to largely improve testability of Structured Streaming state transition functions.Usage Example
Does this PR introduce any user-facing change?
Yes, the
TestGroupState
interface and its correspondingcreate()
factory function in its companion object are introduced in this pull request for users to use in unit tests.How was this patch tested?